<?php  
/**
* 
*/
class Reference_Model extends CI_Model
{
	
	function __construct()
	{
		# code...
		parent::__construct();
	}

	public function getAllReference(){
		return $this->db->get('Mst_reference')->result_array();
	}

	public function getAllTitle(){
		return $this->db->get_where('Mst_reference',array('ref_group'=>'title','ref_status'=> 'A'))->result_array();
	}

	public function getAllPosition(){
		return $this->db->get_where('Mst_reference',array('ref_group'=>'position','ref_status'=> 'A'))->result_array();
	}

	public function getAllDepartment(){
		return $this->db->get_where('Mst_reference',array('ref_group'=>'department','ref_status'=> 'A'))->result_array();
	}

	public function getAllSubDepartment(){
		return $this->db->get_where('Mst_reference',array('ref_group'=>'sub_department','ref_status'=> 'A'))->result_array();
	}

	public function getAllGroup(){
		return $this->db->select('ref_group')->group_by("ref_group")->get('Mst_reference')->result_array();
	}

	public function insert($newRef){
		$this->db->insert('Mst_reference',$newRef);
	}

	public function update($id,$newData){
		$this->db->where('ref_id',$id)->update('Mst_reference',$newData);
	}

	public function getLastReferenceID(){
		$rs = $this->db->query('SELECT TOP 1 ref_id FROM Mst_reference ORDER BY ref_id DESC')->row_array();
		return $rs['ref_id'];
	}

	public function getLastCodeFromGroup($group){
		$rs = $this->db->query('SELECT TOP 1 ref_group, ref_code FROM Mst_reference WHERE ref_group = "'.$group.'" ORDER BY ref_code DESC')->row_array();
		return $rs['ref_code'];
	}

	public function getReferenceWithID($id){
		return $this->db->get_where('Mst_reference',array('ref_id'=>$id))->row_array();
	}





}
?>